package com.app.biz.controller.formal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.app.common.core.page.TableDataInfo;
import com.app.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.enums.BusinessType;
import com.app.biz.domain.formal.BizDailyPowerConsumption;
import com.app.biz.service.IBizDailyPowerConsumptionService;

/**
 * 每天耗电量Controller
 *
 * @author ruoyi
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/biz/dat/formal")
public class BizDailyPowerConsumptionController extends BaseController
{
    @Autowired
    private IBizDailyPowerConsumptionService bizDailyPowerConsumptionService;

    /**
     * 查询每天耗电量列表
     */
//    @PreAuthorize("@ss.hasPermi('system:consumption:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizDailyPowerConsumption bizDailyPowerConsumption)
    {
        startPage();
        List<BizDailyPowerConsumption> list = bizDailyPowerConsumptionService.selectBizDailyPowerConsumptionList(bizDailyPowerConsumption);
        return getDataTable(list);
    }


    /**
     * 插入当天的数据
     * @return
     */
    @PreAuthorize("@ss.hasPermi('biz:dat:insert')")
    @PostMapping("/insertPowerDay")
    public AjaxResult insertPowerDay(@RequestBody BizDailyPowerConsumption bizDailyPowerConsumption){
        return bizDailyPowerConsumptionService.insertPowerDay(bizDailyPowerConsumption);
    }

    @PreAuthorize("@ss.hasPermi('biz:dat:update')")
    @PutMapping("/updatePowerDay")
    public AjaxResult updatePowerDay(@RequestBody BizDailyPowerConsumption bizDailyPowerConsumption){
        return bizDailyPowerConsumptionService.updatePowerDay(bizDailyPowerConsumption);
    }

    /**
     * 更新或者是插入每天的耗电量
     * @param bizDailyPowerConsumption
     * @return
     */
    @PostMapping("/insertOrUpdateDay")
    public AjaxResult insertOrUpdateDay(@RequestBody BizDailyPowerConsumption bizDailyPowerConsumption){
        return bizDailyPowerConsumptionService.insertOrUpdateDay(bizDailyPowerConsumption);
    }

    /**
     * 导出每天耗电量列表
     */
//    @PreAuthorize("@ss.hasPermi('system:consumption:export')")
    @Log(title = "每天耗电量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDailyPowerConsumption bizDailyPowerConsumption)
    {
        List<BizDailyPowerConsumption> list = bizDailyPowerConsumptionService.selectBizDailyPowerConsumptionList(bizDailyPowerConsumption);
        ExcelUtil<BizDailyPowerConsumption> util = new ExcelUtil<BizDailyPowerConsumption>(BizDailyPowerConsumption.class);
        util.exportExcel(response, list, "每天耗电量数据");
    }

    /**
     * 获取每天耗电量详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:consumption:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizDailyPowerConsumptionService.selectBizDailyPowerConsumptionByBaseId(baseId));
    }

    /**
     * 新增每天耗电量
     */
//    @PreAuthorize("@ss.hasPermi('system:consumption:add')")
    @Log(title = "每天耗电量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDailyPowerConsumption bizDailyPowerConsumption)
    {
        return toAjax(bizDailyPowerConsumptionService.insertBizDailyPowerConsumption(bizDailyPowerConsumption));
    }

    /**
     * 修改每天耗电量
     */
//    @PreAuthorize("@ss.hasPermi('system:consumption:edit')")
    @Log(title = "每天耗电量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDailyPowerConsumption bizDailyPowerConsumption)
    {
        return toAjax(bizDailyPowerConsumptionService.updateBizDailyPowerConsumption(bizDailyPowerConsumption));
    }

    /**
     * 删除每天耗电量
     */
//    @PreAuthorize("@ss.hasPermi('system:consumption:remove')")
    @Log(title = "每天耗电量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizDailyPowerConsumptionService.deleteBizDailyPowerConsumptionByBaseIds(baseIds));
    }
}
